// import BaseMap from "./BaseMap";

declare global {
  interface Window {
    PIE: any;
  }
}
class VectorLayers {
  public featureLayer: any = null;
  options: Object;
  viewer: Object;
  globe: any;
  constructor(viewer: any) {
    this.viewer = viewer;
    // this.viewer = VectorLayers.viewer;
    this.options = {};
    this.globe = viewer.getGlobe();
  }
  //加载图层
  addLayer() {
    let workspace = this.globe.getDocument(); //获取工作空间
    let featureDataSource = new PIE.GSFDataSource();
    featureDataSource.load({ gsfUrl: 'data/Provinces_R.gsf' }).then(() => {
      workspace.getDataSourceManager().addDataSource(featureDataSource); //添加数据源
    });
    if (this.featureLayer == null) {
      /**创建风格**/
      var vectorStyle = new PIE.VectorStyle({
        lineColor: [255, 0, 0, 255],
        lineWidth: 1,
        fillColor: [0, 255, 0, 255]
      });
      /**创建渲染器**/
      let featureRenderer = new PIE.SimpleFeatureRenderer();
      featureRenderer.setStyle(vectorStyle);
      this.featureLayer = new PIE.GlobeFeatureLayer();
      this.featureLayer.setDataSource(featureDataSource);
      this.featureLayer.setRenderer(featureRenderer);
      this.globe.addLayer(this.featureLayer, true);
      this.globe.refresh(true, false);
    }
  }

}
export default VectorLayers;